package com.fare.taluo.application.impl.crawl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.crawl.FligthStatusInfoApplication;
import com.fare.taluo.core.domain.crawl.FligthStatusInfoEntity;
import com.fare.taluo.vo.crawl.FligthStatusInfoVO;
import com.google.common.collect.Lists;
@Transactional
@Scope("singleton")
@Service("fligthStatusInfoApplication")
public class FligthStatusInfoApplicationImpl implements FligthStatusInfoApplication{

	@Override
	public List<FligthStatusInfoVO> findAll() {
		FligthStatusInfoEntity en=new FligthStatusInfoEntity();
		List<FligthStatusInfoEntity>listEntity=Lists.newArrayList();
		listEntity=en.findAll();
		if(listEntity.size()>0){
			List<FligthStatusInfoVO> listVo=new ArrayList<FligthStatusInfoVO>();
			for(FligthStatusInfoEntity entity:listEntity){
				FligthStatusInfoVO vo=new FligthStatusInfoVO();
				vo=EntityTrVo(entity);
				listVo.add(vo);
			}
			return listVo;
		}
		return null;
	}

	@Override
	public List<FligthStatusInfoVO> findByCondition(String grabDateStr) {
		FligthStatusInfoEntity en=new FligthStatusInfoEntity();
		List<FligthStatusInfoEntity>listEntity=Lists.newArrayList();
		if(grabDateStr !=null && !"".equals(grabDateStr)){
			listEntity=en.findByGrabDate(grabDateStr);
		}else{
			listEntity=en.findAll();
		}
		if(listEntity.size()>0){
			List<FligthStatusInfoVO> listVo=new ArrayList<FligthStatusInfoVO>();
			for(FligthStatusInfoEntity entity:listEntity){
				FligthStatusInfoVO vo=new FligthStatusInfoVO();
				vo=EntityTrVo(entity);
				listVo.add(vo);
			}
			return listVo;
		}
		return null;
	}

	@Override
	public void updateVo(FligthStatusInfoVO updateVo) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void save(FligthStatusInfoVO vo) {
		FligthStatusInfoEntity en=new FligthStatusInfoEntity();
		en.setCreateTime(vo.getCreateTime());
		en.setGrabDate(vo.getGrabDateStr());
		en.setPath(vo.getPath());
		en.setTitle(vo.getTitle());		
		en.saveOrUpdateUserCareLineEntity(en);
	}
	
	public FligthStatusInfoVO EntityTrVo(FligthStatusInfoEntity entity){
		FligthStatusInfoVO vo=new FligthStatusInfoVO();
		vo.setId(entity.getId());
		vo.setCreateTime(entity.getCreateTime());
		vo.setGrabDateStr(entity.getGrabDate());
		vo.setPath(entity.getPath());
		vo.setTitle(entity.getTitle());		
		return vo;
	}

}
